#ifndef FANCTRL_H
#define FANCTRL_H

//初始化调用: FanCtrlInit();
//主循环调用: 
//  HeatingFanCtrl();
//  ExhaustFanCtrl();
//  IgniterCtrl();
//定时器 Tick 10ms调用: FanCtrlClock();
//控制所有温控设备准备工作: FanCtrlStart();
//控制所有温控设备停止工作: FanCtrlStop();

#include "Main.h"
//#include "../chip.h"

#define SmokeTempSetting 165 //°F
#define HighTempSetting 450  //°F
#define SmokeTempMeatSetting 140 //°F
#define HighTempMeatSetting 215 //°F



#define FanClose_CountDown 600 //切换到Shut Down档位后,排气扇打开持续该时间后关闭
#define FanClose_Delay_Time (FanClose_CountDown) //10s,用于显示OFF的时间,闪耀4次

#define IO_Igniter PORT_B_11 //点火棒 
#define IO_Feed PORT_B_13 //马达
#define IO_Fan PORT_B_12 //风扇

#define IO_Mode_Igniter MR88FX02_Gpio_Set_Mode(IO_Igniter,OUTPUT);
#define IO_Mode_Feed MR88FX02_Gpio_Set_Mode(IO_Feed,OUTPUT);
#define IO_Mode_Fan MR88FX02_Gpio_Set_Mode(IO_Fan,OUTPUT);

#define IO_Write_H_Igniter MR88FX02_Gpio_Set(IO_Igniter,1);
#define IO_Write_H_Feed MR88FX02_Gpio_Set(IO_Feed,1);
#define IO_Write_H_Fan MR88FX02_Gpio_Set(IO_Fan,1);
#define IO_Write_L_Igniter MR88FX02_Gpio_Set(IO_Igniter,0);
#define IO_Write_L_Feed MR88FX02_Gpio_Set(IO_Feed,0);
#define IO_Write_L_Fan MR88FX02_Gpio_Set(IO_Fan,0);

//原理图上: 输出高电平风扇停止, 输出低电平风扇运行
#define IgniterOpen {IO_Write_H_Igniter;igniter_state = 1;} //开始加热点火输出 (紫色线)
#define IgniterClose {IO_Write_L_Igniter;igniter_state = 0;} //停止加热点火输出
#define HeaterFanOpen {IO_Write_H_Feed;motor_state = 1;}   //开始进料加热输出 (红色线)
#define HeaterFanClose {IO_Write_L_Feed;motor_state = 0;} //停止进料加热输出
#define ExhaustFanOpen {IO_Write_H_Fan;fan_state = 1;} //开始排气扇输出 (橙色线)
#define ExhaustFanClose {IO_Write_L_Fan;fan_state = 0;} //停止排气扇输出

//以下两个参数,需要提供
extern uint16_t temp_set;
extern uint8_t Smoke_P_Value;
extern uint8_t IgniterStep;
extern uint8_t HeatingFanStep;
extern uint16_t ExhaustFanClock; //if(ExhaustFanClock > 0) 显示OFF跟关机倒计时




#if Debug_Hand_PID == 1
extern float Hand_PID_TD;
#endif
void FanCtrl_IOConfig(void);
void FanCtrlInit(void);
void FanCtrlClock(void);
void FanCtrlStart(void);
void FanCtrlStop(void);
void FanCtrlForceStop(void);
void HeatingFanCtrl(void);
void ExhaustFanCtrl(void);
void IgniterCtrl(void);
void Load_Ctrl(void);

#endif
